home *** CD-ROM | disk | FTP | other *** search
- #include <stdlib.h>
- #include <stdio.h>
- #include <conio.h>
- #include <dir.h>
- #include <dos.h>
- #include <time.h>
- #include <async.h>
- #include <process.h>
- #include "hsend.h"
-
- int WAITING,BAUD,COMM,RINGS,SCREENFLAG,LOGFILEFLAG,FLAGFILEFLAG;
- int HARDERR_FLAG=0,TIMEOUT=180;
- char LOGFILE[61],FLAGFILE[61],PASSWORD[13];
- ASYNC *P=NULL;
-
-
- main(argc,argv)
- int argc;
- char argv[];
- {
- ctrlbrk(break_handler);
- harderr(hardware_error_handler);
- load_data();
-
- if(argc>2){
- cprintf("\n\rUsage: hsend <no arguments> Run in host mode\n\r");
- cprintf(" hsend <batch file name> Run in guest mode\n\r");
- beep(3,400);
- exit(1);}
-
- copyright();
-
- if(!init_modem()){
- gotoxy(1,21);
- textcolor(LIGHTGRAY);
- cprintf("\n\rCOMM device did not respond. Check settings with CONFIGUR.\n\r");
- beep(3,400);
- exit(1);}
-
- clrscr();
- textcolor(LIGHTCYAN);
- empty_box(1,1,80,20);
- empty_box(1,21,80,24);
-
- if(argc==2) guest_mode(argv[2]);
- else host_mode();
-
- window(1,1,80,25);
- gotoxy(3,22);
- textcolor(LIGHTMAGENTA);
- cprintf("Initializing modem, please wait...");
- init_modem();
- a_close(P,0);
-
- textcolor(LIGHTGRAY);
- textbackground(BLACK);
- clrscr();
- exit(0);
- }
-
-
- void host_mode(void)
- {
- int x,y;
- char temp[80];
- struct tm *ptr;
- time_t lt;
-
- TIMEOUT*=2; /* wait longer if in host mode */
- gotoxy(29,1);
- cprintf(" H-SEND Host Mode V1.0 ");
- window(4,2,77,18);
-
- for(;;){
- bottom(&x,&y);
- cprintf("Modem is currently OFF-LINE. Press ESC to exit.");
- a_printf(P,"AT S0=%d V0\n\r",RINGS);
- do{
- if(kbhit()) if(getch()==27){ /* ESC key to exit */
- clrscr();
- return;}
- }while(OFFLINE); /* wait here for carrier */
-
- cprintf("\n\rModem is currently ON-LINE");
- lt=time(NULL);
- ptr=localtime(<);
- strcpy(temp,"On-line: ");
- strcat(temp,asctime(ptr));
- strcat(temp,"\n\r");
- report(temp);
- top(x,y);
- if(password_check()) while(cmd_mode(1));
- init_modem();
- init_modem(); /* make sure modem is reset */
- }
- }
-
-
- int guest_mode(batchfile)
- char *batchfile;
- {
- FILE *fp;
- char str[100],temp[80],*buf;
- int i,x,y,flag=1;
- struct tm *ptr;
- time_t lt;
-
- if(FLAGFILEFLAG) remove(FLAGFILE);
-
- strcpy(str,"Executing: ");
- strcat(str,batchfile);
- gotoxy(39-strlen(batchfile),1);
- cprintf(" %s ",str);
- window(4,3,77,18);
-
- AGAIN:
- if((fp=fopen(batchfile,"r"))==NULL){
- report("ERROR- Unable to open batchfile");
- return 0;} /* return error condition */
- do{
- if(fgets(str,100,fp)){
- for(i=0;i<strlen(str);i++)
- if(str[i]=='\n' || str[i]=='\r') str[i]=NULL;
- strupr(str);
- textcolor(WHITE);
- report("");
- report(str);
- textcolor(LIGHTCYAN);
- flag=interpret_batch_cmd(str);}
- }while(!feof(fp) && !flag && !HARDERR_FLAG);
-
- scb(EOC,0,NULL);
- lt=time(NULL);
- ptr=localtime(<);
- strcpy(temp,"Call terminated: ");
- strcat(temp,asctime(ptr));
- report(temp);
- fclose(fp);
- if(flag || HARDERR_FLAG){
- report("ON-LINE transfer was not sucessful");
- x=wherex(); y=wherey();
- if((buf=malloc(2*44*9))==NULL) exit(1);
- gettext(18,5,62,13,buf);
- window(18,5,62,13);
- textbackground(LIGHTCYAN);
- textcolor(WHITE);
- clrscr();
- empty_box(2,1,44,9);
- gotoxy(11,1);
- cprintf(" Data Transfer Failure ");
- gotoxy(5,4);
- cprintf("The transfer has not been completed.");
- beep(1,300);
- beep(1,1000);
- do{
- gotoxy(5,6);
- cprintf("Would you like to try again? <Y or N>");
- i=getch();
- i=toupper(i);
- if(i!='Y' && i!='N') beep(1,1000);
- }while(i!='Y' && i!='N');
- cprintf("%c",i);
- textbackground(BLACK);
- window(4,3,77,18);
- puttext(18,5,62,13,buf);
- gotoxy(x,y);
- if(i=='Y') goto AGAIN;
-
- window(4,3,77,18);
- puttext(18,5,62,13,buf);
- return 0;}
-
- else{
- report("No error occurred");
- if(FLAGFILEFLAG) if((fp=fopen(FLAGFILE,"a"))==NULL){
- if((fp=fopen(FLAGFILE,"r"))==NULL) report("Unable to create flagfile");}
- return 1;}
-
- }
-
-
- int cmd_mode(host_flag) /* return 0 at end of sesssion */
- {
- unsigned char buf[518];
- int cmdreq;
-
- for(;;){
- if(host_flag){
- if(!scb(OKTS,0,NULL)){ /* OK to send */
- report("ERROR- OKTS transmission not acknowledged");
- return 0;}}
-
-
- do{ /* receiving command */
- if(OFFLINE){
- report("DATA CONNECTION LOST");
- return 0;}
- cmdreq=rcb(0,buf);
- }while(!cmdreq);
-
- switch(cmdreq){
-
- case OKTS: return -1;
-
- case SFR: send_file_request(buf,0);
- break;
-
- case IFR: create_local_file(buf);
- break;
-
- case DF: delete_files(buf,HOST);
- break;
-
- case EM: error_message(buf);
- break;
-
- case EOC: report("Transmission terminated normally");
- return 0;
-
- case RESTART: report("Restarting hsend...");
- execlp("hsend.exe",NULL,NULL);
-
- default: report("cmd_mode() default");
- if(!host_flag) return -1;} /* switch back to active mode */
-
-
- } /* endless loop */
- }
-
-
- int passive(void) /* switch to passive mode */
- {
- int status;
-
- for(;;){
- status=cmd_mode(0); /* will be executing received commands while here */
-
- if(!status) return 1; /* outgoing command not acknowledged, returning 1 will
- cause guest_mode() to exit with an error condition */
-
- if(status==-1) return 0; /* OKTS received, switch back to send mode */
-
- } /* endless loop */
- }
-
-
- int interpret_batch_cmd(cmd)
- char *cmd;
- {
- char temp[512],from[100],to[100];
- int i;
-
- if(strlen(cmd)<4) return 0; /* ignore trash */
-
- if(!strncmp(cmd,"CALL",4)) return(call_remote(cmd));
-
- if(!strncmp(cmd,"REM",3)) return 0; /* remarks */
-
- if(scb(EM,2," ")) if(!rcb(OKTS,temp)) rcb(OKTS,temp); /* send a blank line */
- if(scb(EM,strlen(cmd)+1,cmd)) if(!rcb(OKTS,temp)) rcb(OKTS,temp); /* send the command */
-
- /*----------------------- COPY FROM HOST TO GUEST --------------------------------*/
- if(!strncmp(cmd,"COPY H",6)){
- parse(cmd);
- if(!seperate(cmd,from,to,' ')){
- report("ERROR- COPY command syntax");
- return 1;}
- for(i=0;i<strlen(from);i++) /* remove H and L designations */
- from[i]=from[i+1];
- for(i=0;i<strlen(to);i++)
- to[i]=to[i+1];
-
- strcpy(temp,from); /* set up SFR string */
- strcat(temp,"|");
- strcat(temp,to);
-
- if(!scb(SFR,strlen(temp)+1,temp)){
- report("ERROR- Host unable to verify SFR transmission");
- return 1;}
- else return passive();}
- /*--------------------------------------------------------------------------------*/
-
- /*----------------------- COPY FROM GUEST TO HOST --------------------------------*/
- if(!strncmp(cmd,"COPY L",6)){
- parse(cmd);
- if(!seperate(cmd,from,to,' ')){
- report("ERROR- COPY command syntax");
- return 1;}
- for(i=0;i<strlen(from);i++) /* remove H and L designations */
- from[i]=from[i+1];
- for(i=0;i<strlen(to);i++)
- to[i]=to[i+1];
-
- strcpy(temp,from); /* set up SFR string */
- strcat(temp,"|");
- strcat(temp,to);
-
- return send_file_request(temp,1);}
- /*--------------------------------------------------------------------------------*/
-
-
- /*-------------------------DELETE FILES-------------------------------------------*/
- if(!strncmp(cmd,"DELETE",6)){
- parse(cmd);
- if(cmd[0]=='H'){
- for(i=0;i<strlen(cmd);i++)
- cmd[i]=cmd[i+1]; /* remove the first character (H) */
- {if(!scb(DF,strlen(cmd)+1,cmd)){
- report("ERROR- Host unable to verify DF transmission");
- return 1;}
- else return passive();}}
- if(cmd[0]=='L'){
- for(i=0;i<strlen(cmd);i++)
- cmd[i]=cmd[i+1]; /* remove the first character (H) */
- delete_files(cmd,GUEST);
- return 0;}}
- /*--------------------------------------------------------------------------------*/
-
- report("ERROR- Command syntax");
- return 1;
- }
-
-
- void report(message)
- char *message;
- {
-
- FILE *fp;
-
- if(SCREENFLAG) cprintf("%s\n\r",message);
-
- if(!LOGFILEFLAG) return;
- if((fp=fopen(LOGFILE,"a"))==NULL){
- if((fp=fopen(LOGFILE,"r"))==NULL) return;}
-
- fprintf(fp,"%s\n\r",message);
- fclose(fp);
- }
-
-
- int init_modem(void)
- {
- int x;
-
- if(P) a_close(P,0);
- P=a_open(COMM,BAUD,0,8,1,8000,2000); /* open at no parity,8 dbits, 1 sbit 8K input ,2k output buffer */
- a_setmcr(P,MCR_DTR+MCR_RTS); /* set DTR and RTS high */
- a_iflush(P); /* clear input buffer */
- sleep(1);
- a_puts("+++",P);
- sleep(2);
- a_puts("\n\rATZ\n\r",P);
- sleep(2);
- a_puts("AT S0=0\n\r",P);
- a_waitquiet(P,18,72,1); /* wait for a reply */
- x=a_icount(P);
- while(a_icount(P)) a_getc(P); /* clear input buffer */
- return x; /* return # of characters in reply */
- } /* 0 return value denotes no modem present */
-
-
- int agetc(void) /* returns 0 if error occurs */
- {
- long timer;
-
- timer=biostime(0,0);
- do{
- if(OFFLINE) return -1; /* no carrier */
- if(a_icount(P)) return a_getc(P);
- }while(biostime(0,0)-timer<TIMEOUT);
-
- report("Timeout");
- return -2;
- }
-
-
- int password_check(void) /* return 1 if password is verified */
- {
- unsigned char temp[518];
-
- cprintf("\n\r\n\rWaiting for password...\n\r");
- sleep(3);
- if(!scb(RP,0,NULL)){
- report("Caller could not verify Requesting Password transmission");
- return 0;}
- if(!rcb(SP,temp)){
- report("Caller did not sent password");
- return 0;}
- if(!strcmp(temp,PASSWORD)) return 1; /* correct password received */
- report("Incorrect password received.");
- return 0;
- }
-
-
- int password_verification(void) /* 0 return value equals password match */
- {
- unsigned char tmp[518];
-
- while(a_icount(P)) a_getc(P); /* clear input buffer */
- /* host will wait 3 seconds before sending request */
- if(!rcb(RP,tmp)) if(!rcb(RP,tmp)){
- report("ERROR- Did not receive 'requesting password' transmission");
- return 1;}
-
- if(!scb(SP,strlen(PASSWORD)+1,PASSWORD)){
- report("ERROR- Host unable to verify password transmission");
- return 1;}
-
- if(!rcb(OKTS,tmp)){
- report("ERROR- did not receive OKTS after host received password transmission");
- return 1;}
-
- /* call will be dropped at host end if password string does not match */
-
- return 0;
- }
-
-
- int call_remote(number)
- char *number;
- {
- char tmp[100];
- int x,y;
- struct tm *ptr;
- time_t lt;
-
- bottom(&x,&y);
- cprintf("Phone call in progress...");
- init_modem();
-
- parse(number);
- a_printf(P,"AT V0 S7=%d X4 TD%s\r",WAITING,number); /* send modem command */
- a_gets(tmp,100,P,36); /* receive echo of command */
- a_gets(tmp,100,P,WAITING*18);
-
- top(x,y);
-
- lt=time(NULL);
- ptr=localtime(<);
- switch(atoi(tmp)){
-
- case 1: if(BAUD==300){
- strcpy(tmp,"300 BPS connection: ");
- strcat(tmp,asctime(ptr));
- report(tmp);
- return(password_verification());}
- else{
- report("ERROR- Unable to connect a proper baud rate");
- return 1;}
-
- case 5: if(BAUD==1200){
- strcpy(tmp,"1200 BPS connection: ");
- strcat(tmp,asctime(ptr));
- report(tmp);
- return(password_verification());}
- else{
- report("ERROR- Unable to connect at proper baud rate");
- return 1;}
-
- case 9:
- case 10: if(BAUD==2400){
- strcpy(tmp,"2400 BPS connection: ");
- strcat(tmp,asctime(ptr));
- report(tmp);
- return(password_verification());}
- else{
- report("ERROR- Unable to connect at proper baud rate");
- return 1;}
-
- case 3: report("ERROR- No carrier");
- return 1;
-
- case 6: report("ERROR- No dialtone");
- return 1;
-
- case 7: report("ERROR- Dialed number is busy");
- return 1;
-
- case 8: report("ERROR- 5 seconds of silence not detected (using @ command)");
- return 1;
-
- default: report("ERROR- Dialing error");
- return 1;}
-
- }
-
-
- int scb(cmd,blklen,blk) /* send command block, returns 1 if acknowledged */
- int cmd; /* #defined command code */
- int blklen; /* number of data characters */
- unsigned char *blk; /* 0 to 512 data characters */
- { /* returns value of carrier detect */
- unsigned char buf[518];
- register int i,try,reply;
- unsigned long cksum;
-
- while(a_icount(P)) a_getc(P); /* clear input buffer */
- buf[3]=cmd; /* command code */
- buf[4]=blklen/255; /* # of data chars hibyte */
- buf[5]=blklen-(buf[4]*255); /* # of data chars lobyte */
-
- if(blklen){ /* if there are data characters */
- for(i=0;i<blklen;i++) /* copy them into buf */
- buf[i+6]=blk[i];}
-
- for(i=3,cksum=0;i<blklen+6;i++) /* add to create checksum */
- cksum+=buf[i];
-
- buf[0]=cksum/65025; /* checksum hibyte */
- cksum-=(long)buf[0]*65025;
- buf[1]=cksum/255; /* checksum midbyte */
- buf[2]=cksum-(long)(buf[1]*255); /* checksum lobyte */
-
- for(try=0;try<TRY;try++){
- for(i=0;i<blklen+6;i++)
- a_putc(buf[i],P); /* send the block */
- reply=agetc();
- if(reply==ACK) return 1; /* OK */
- if(reply==-1) return 0; /* no carrier */
- if(reply!=NAK) while(a_icount(P)) a_getc(P);} /* remove the trash */
-
- return 0;
- }
-
-
- int rcb(cmd,blk) /* receive command block */
- int cmd; /* expected reply command */
- unsigned char *blk; /* fills blk with data chars received */
- { /* returns 0 if cannot verify block on TRY attempts */
- long cksum,tempsum;
- unsigned char buf[518];
- register int i;
- int tmp,charcount;
-
- for(i=0;i<6;i++){ /* get first 6 characters */
- tmp=agetc();
- if(tmp<0) return 0;
- buf[i]=tmp;}
-
- charcount=(buf[4]*255)+buf[5]; /* get remaining data characters */
- if(charcount){
- for(i=6;i<charcount+6;i++){
- tmp=agetc();
- if(tmp<0) return 0; /* no carrier or timeout */
- buf[i]=tmp;
- blk[i-6]=tmp;}}
-
- for(tempsum=0,i=3;i<charcount+6;i++) /* create checksum of chars received */
- tempsum+=buf[i];
-
- cksum=(long)buf[0]*65025; /* create cheksum sent with data */
- cksum+=(long)buf[1]*255;
- cksum+=buf[2];
-
- if(cmd==0) cmd=buf[3]; /* unknown command expected */
-
- if(cksum==tempsum && cmd!=buf[3]) return 0;
-
- {if(cksum==tempsum && cmd==buf[3]){
- a_putc(ACK,P);
- return buf[3];} /* block OK returning cmd received */
- else{
- a_putc(NAK,P); /* block not OK */
- return 0;}}
- }
-
-
- int rdb(cmd,blk) /* receive data block */
- int cmd; /* expected reply command */
- unsigned char *blk; /* fills blk with data chars received */
- { /* returns 0 if cannot verify block on TRY attempts */
- long cksum,tempsum;
- unsigned char buf[518];
- register int i;
- int tmp,charcount;
-
- for(i=0;i<6;i++){ /* get first 6 characters */
- tmp=agetc();
- if(tmp<0) return -1;
- buf[i]=tmp;}
-
- charcount=(buf[4]*255)+buf[5]; /* get remaining data characters */
- if(charcount){
- for(i=6;i<charcount+6;i++){
- tmp=agetc();
- if(tmp<0) return -1; /* no carrier or timeout */
- buf[i]=tmp;
- blk[i-6]=tmp;}}
-
- for(tempsum=0,i=3;i<charcount+6;i++) /* create checksum of chars received */
- tempsum+=buf[i];
-
- cksum=(long)buf[0]*65025; /* create cheksum sent with data */
- cksum+=(long)buf[1]*255;
- cksum+=buf[2];
-
- if(cmd==0) cmd=buf[3]; /* unknown command expected */
-
- if(cksum==tempsum && cmd!=buf[3]) return 0;
-
- {if(cksum==tempsum && cmd==buf[3]){
- a_putc(ACK,P);
- return charcount;} /* block OK returning cmd received */
- else{
- a_putc(NAK,P); /* block not OK */
- return -1;}}
- }
-
-
- int create_local_file(filespec)
- char *filespec;
- {
- unsigned char buf[518];
- char tmp[100];
- FILE *fp;
- int charcount,i,try,x,y;
- long size=0;
-
- strcpy(tmp,"Creating local file: ");
- strcat(tmp,filespec);
- report(tmp);
-
-
- if((fp=fopen(filespec,"wb"))==NULL){ /* open the file */
- strcpy(tmp,"ERROR- Unable to create file");
- report(tmp);
- scb(EM,strlen(tmp),tmp);
- return 1;}
-
- if(!scb(IFS,0,NULL)){ /* start sending now */
- report("ERROR- Host unable to verify IFS transmission");
- fclose(fp);
- return 1;}
-
- bottom(&x,&y);
- cprintf("File transfer in progress...\n\rBytes received: 0");
-
- try=1;
- do{
- charcount=rdb(SDB,buf);
- if(OFFLINE){
- fclose(fp);
- top(x,y);
- report("ERROR- file transfer aborted (connection lost)");
- return 1;} /* no carrier */
- if(++try>TRY && charcount<0){
- fclose(fp);
- top(x,y);
- report("ERROR- file transfer aborted (receiving error)");
- return 1;}
- if(charcount){
- try=1;
- for(i=0;i<charcount;i++){
- if(ferror(fp)){
- fclose(fp);
- top(x,y);
- report("ERROR- File transfer aborted (I/O error)");
- return 1;}
- fputc(buf[i],fp);}}
- size+=charcount;
- gotoxy(1,2);
- cprintf("Bytes received: %ld",size);
- }while(charcount); /* stop when you rec. an empty block */
-
- i=ferror(fp);
- fclose(fp);
- top(x,y);
- return i; /* non zero equals error condition */
- }
-
-
- void error_message(msg)
- char *msg;
- {
- char temp[200];
- if(strlen(msg)>2) strcpy(temp,"Remote: ");
- else strcpy(temp," ");
- strcat(temp,msg);
- report(temp);
-
- }
-
-
- void delete_files(filespec,hostflag)
- char *filespec;
- int hostflag; /* set to 0 if deleting a file while in guest mode */
- {
- char temp[150],path[100],pathname[116];
- struct ffblk f;
- int i;
-
- strcpy(temp,"Deleting file(s): ");
- strcat(temp,filespec);
- report(temp);
-
- strcpy(path,filespec); /* create a path for remove command */
- for(i=strlen(path);i>0;i--){
- if(path[i]=='\\') break;
- path[i]=NULL;}
-
- if(findfirst(filespec,&f,0)){
- strcpy(temp,"No file(s) to delete");
- report(temp);
- if(hostflag) scb(EM,strlen(temp)+1,temp);
- return;}
-
- do{
- strcpy(temp,f.ff_name); /* temp used to report what files deleted */
-
- strcpy(pathname,path); /* pathname is file to remove */
- strcat(pathname,f.ff_name);
-
- {if(!remove(pathname)){
- for(i=0;i<14-strlen(f.ff_name);i++)
- strcat(temp," ");
- strcat(temp,"deleted");
- report(temp);
- if(hostflag) scb(EM,strlen(temp)+1,temp);}
- else{
- for(i=0;i<14-strlen(f.ff_name);i++)
- strcat(temp," ");
- strcat(temp,"cannot be deleted");
- report(temp);
- if(hostflag) scb(EM,strlen(temp)+1,temp);}}
-
- }while(!findnext(&f));
- }
-
-
- int send_file_request(fromto,send_OKTS_flag) /* returns 1 if error, 0 on success */
- unsigned char *fromto; /* holds name of files to send */
- int send_OKTS_flag; /* set to 1 if sending from guest to host */
- {
- struct ffblk f;
- int i,c,errflag=0;
- char source_pathname[200],dest_pathname[200],tmp[518],from[200],to[200];
- char s[15],d[15];
-
- if(!seperate(fromto,from,to,'|')){
- error_message("Source/destination seperation error");
- return 1;}
-
- if(findfirst(from,&f,0)){
- report("No files to send\n");
- return 0;}
-
- do{
- strcpy(source_pathname,from); /* create a full source pathname */
-
- for(i=strlen(source_pathname);i>0;i--){
- if(source_pathname[i]=='\\') break;
- source_pathname[i]=NULL;}
-
- strcat(source_pathname,f.ff_name);
-
- strcpy(dest_pathname,to); /* create a full dest. pathname */
- for(i=strlen(dest_pathname);i>0;i--){
- if(dest_pathname[i]=='\\') break;
- dest_pathname[i]=NULL;}
-
- strcpy(s,eight_plus_three(f.ff_name,'?')); /* store 8+3 filename in s */
-
- for(c=0,i=strlen(to)-1;i>0;i--){ /* store 8+3 filename in d */
- if(to[i]=='\\') break;
- tmp[c++]=to[i];}
- tmp[c]=NULL;
- strrev(tmp);
- strcpy(d,eight_plus_three(tmp,'@'));
-
- for(i=0;i<8;i++){ /* convert the * char to ? */
- if(d[i]=='*'){
- for(;i<8;i++)
- d[i]='?';}}
- for(i=9;i<12;i++){
- if(d[i]=='*'){
- for(;i<12;i++)
- d[i]='?';}}
-
- for(i=0;i<12;i++) /* lay s on d */
- if(d[i]!='@') if(s[i]!='?' && d[i]=='?') d[i]=s[i];
-
- for(i=0;i<12;i++) /* remove trash */
- if(d[i]=='@' || d[i]=='?') d[i]=' ';
-
- for(i=0,c=0;i<12;i++) /* remove spaces */
- if(d[i]!=' ') tmp[c++]=d[i];
- tmp[c]=NULL;
-
- strcat(dest_pathname,tmp); /* add to filename to path */
- strupr(dest_pathname);
-
- errflag=initiate_file_send(source_pathname,dest_pathname); /* send the file */
- if(send_OKTS_flag) if(!rcb(OKTS,tmp)) rcb(OKTS,tmp);
-
- }while(!findnext(&f) && !errflag);
- return errflag;
- }
-
-
- int initiate_file_send(from,to) /* returns 1 on error, 0 if OK */
- char *from,*to;
- {
- unsigned char temp[518],buf[518];
- long sent=0;
- int i,x,y;
- struct ffblk f;
- FILE *fp;
-
- if(findfirst(from,&f,0)){
- report("Error reading filesize from directory");
- return 1;}
-
- strcpy(temp,"Dest: ");
- strcat(temp,to);
- report(temp);
-
- scb(IFR,strlen(to)+1,to); /* send null terminated pathname */
-
- if(!rcb(IFS,temp)){ /* OK to send file? */
- report("Error creating remote file");
- return 1;}
-
- if((fp=fopen(from,"rb"))==NULL){
- strcpy(temp,"Unable to read file: ");
- strcat(temp,from);
- report(temp);
- return 1;}
-
- bottom(&x,&y);
- cprintf("File transfer in progress...\n\rFile size: %ld Bytes sent: %ld",f.ff_fsize,sent);
- do{
- for(i=0;i<512;i++){
- if(feof(fp) || ferror(fp)) break;
- sent++;
- buf[i]=fgetc(fp);}
- if(feof(fp) || ferror(fp)){
- sent--;
- if(i) i--;} /* don't send an extra character */
- if(!scb(SDB,i,buf)){
- strcpy(temp,"Unable to verify SDB transmission");
- scb(EM,strlen(temp)+1,temp);
- fclose(fp);
- top(x,y);
- report(temp);
- return 1;}
-
- gotoxy(1,2);
- cprintf("File size: %ld Bytes sent: %ld",f.ff_fsize,sent);
- }while(i);
-
- if(ferror(fp)){
- strcpy(temp,"ERROR- reading file");
- top(x,y);
- report(temp);
- scb(EM,strlen(temp)+1,temp);}
-
- fclose(fp);
- top(x,y);
- return 0;
- }
-
-
- int load_data(void)
- {
- FILE *fp;
- if((fp=fopen(DATAFILE,"r"))==NULL){
- cprintf("\n\rUnable to open configuration file %s\n\r",DATAFILE);
- perror("Reason");
- cprintf("\n\rRun CONFIGUR to create a new config file.\n\r");
- beep(3,400);
- exit(1);}
-
- else{
- fread(&BAUD,sizeof(BAUD),1,fp);
- fread(&COMM,sizeof(COMM),1,fp);
- fread(&RINGS,sizeof(RINGS),1,fp);
- fread(&SCREENFLAG,sizeof(SCREENFLAG),1,fp);
- fread(&LOGFILEFLAG,sizeof(LOGFILEFLAG),1,fp);
- fread(&LOGFILE,sizeof(LOGFILE),1,fp);
- fread(&FLAGFILEFLAG,sizeof(FLAGFILEFLAG),1,fp);
- fread(&FLAGFILE,sizeof(FLAGFILE),1,fp);
- fread(&PASSWORD,sizeof(PASSWORD),1,fp);
- fread(&WAITING,sizeof(WAITING),1,fp);
- fclose(fp);}
-
- return 1;
- }
-
-
- void copyright(void)
- {
- system("cls");
- textbackground(BLACK);
- textcolor(LIGHTCYAN);
- empty_box(20,8,65,14);
- gotoxy(29,10);
- cprintf("H-SEND File Transfer System");
- gotoxy(22,12);
- cprintf("(C) John Hutchey 1991 All Rights Reserved");
- }
-
-
- int break_handler(void)
- {
- window(1,1,80,25);
- clrscr();
- textcolor(LIGHTGRAY);
- textbackground(BLACK);
- printf("Control-Break interrupt.\n");
- return 0;
- }
-
-
- void empty_box(start_x,start_y,end_x,end_y)
- int start_x,start_y,end_x,end_y;
- {
- int x,y;
-
- /* set up corners */
- gotoxy(start_x,start_y);
- cprintf("%c",201);
- gotoxy(end_x,start_y);
- cprintf("%c",187);
- gotoxy(start_x,end_y);
- cprintf("%c",200);
- gotoxy(end_x,end_y);
- cprintf("%c",188);
-
- /* top & bottom line */
- for(x=start_x+1;x<end_x;x++){
- gotoxy(x,start_y);
- cprintf("%c",205);
- gotoxy(x,end_y);
- cprintf("%c",205);}
-
- /* side lines */
- for(y=start_y+1;y<end_y;y++){
- gotoxy(start_x,y);
- cprintf("%c",186);
- gotoxy(end_x,y);
- cprintf("%c",186);}
-
- }
-
-
- void beep(loop,freq)
- int loop,freq;
- {
- int i;
- unsigned char p;
- long timer;
-
- union{
- long divisor;
- unsigned char c[2];
- }count;
-
- for(i=0;i<loop;i++){
- count.divisor=1193280/freq;
- outportb(67,182);
- outportb(66,count.c[0]);
- outportb(66,count.c[1]);
- p=inportb(97);
- outportb(97,p|3);
-
- timer=biostime(0,0);
- while(biostime(0,0)-timer<3);
-
- outportb(97,p);
-
- timer=biostime(0,0);
- while(biostime(0,0)-timer<1);}
- }
-
-
- int seperate(combined,first,second,seperator)
- char *combined,*first,*second,seperator;
- {
- int i,c;
-
- for(i=0;i<strlen(combined);i++)
- if(combined[i]==seperator) break;
- if(i==strlen(combined)) return 0; /* no seperator present in string */
-
- for(i=0;i<strlen(combined);i++){
- if(combined[i]==seperator) break;
- first[i]=combined[i];}
- first[i]=NULL; /* first half of *combined copied to *first */
-
- for(i++,c=0;i<=strlen(combined);i++)
- second[c++]=combined[i]; /* second half of *combined copied to *second */
-
- return 1; /* OK */
- }
-
-
- char *eight_plus_three(source,fill)
- char *source;
- char fill;
- {
- static char a[15];
- char b[5];
- char filler[2];
-
- filler[0]=fill;
- filler[1]=NULL;
-
- if(!seperate(source,a,b,'.')){
- strcpy(a,source);
- b[0]=NULL;}
-
- while(strlen(a)<8) strcat(a,filler); /* pad to 8 chars */
- strcat(a,"."); /* add a period */
- strcat(a,b); /* add extension */
- while(strlen(a)<12) strcat(a,filler); /* pad to 12 chars */
- return a; /* return pointer to converted string */
- }
-
-
- void parse(str) /* remove chars up to and including first space character */
- char *str;
- {
- char temp[120];
- int i=0,n=0;
-
- while(str[i]!=' ') i++;
-
- for(i++;i<strlen(str);i++){
- if(n==119){
- printf("Error- command string too long!\n%s\n",str);
- break;}
- temp[n++]=str[i];}
-
- temp[n]=NULL;
- strcpy(str,temp);
- }
-
-
- void top(x,y) /* Switch to top window */
- int x,y;
- {
- clrscr();
- window(4,3,77,18);
- gotoxy(x,y);
- textcolor(LIGHTCYAN);
- }
-
-
- void bottom(x,y) /* Switch to bottom window */
- int *x,*y;
- {
- *x=wherex();
- *y=wherey();
- window(4,22,79,23);
- textcolor(LIGHTMAGENTA);
- clrscr();
- }
-
-
- hardware_error_handler(int errnum,int ax,int bp,int si)
- {
- report("Hardware error intercepted");
- HARDERR_FLAG++;
- hardretn(2);
- }